home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
54200
/
54200.xpi
/
chrome
/
dogood.jar
/
content
/
DoGoodContextMenu.js
< prev
next >
Wrap
Text File
|
2010-01-05
|
7KB
|
230 lines
/**
* Context menu handler
*/
const DoGoodContextMenu =
{
context_menu_showorigall : null,
context_menu_report : null,
context_menu_ignoreon : null,
context_menu_ignoreoff : null,
context_menu : null,
toolbar_menu_showorigall : null,
toolbar_menu_ignoreon : null,
toolbar_menu_ignoreoff : null,
/**
* Event handler to open the context menu
*
*/
DoGoodContextOn : function() {
var doc = window.content.document;
if (gContextMenu.onLink && gContextMenu.onImage && !DoGoodCookie.isIgnore(doc.location.href) && !gContextMenu.target.is_dogood && (gContextMenu.target.id != 'DoGoodObject')) {
DoGoodContextMenu.context_menu_report.setAttribute('hidden', false);
} else {
DoGoodContextMenu.context_menu_report.setAttribute('hidden', true);
}
if (DoGoodReplace.isDogoodObject(doc)) {
DoGoodContextMenu.context_menu_showorigall.setAttribute('hidden', false);
} else {
DoGoodContextMenu.context_menu_showorigall.setAttribute('hidden', true);
}
if (DoGoodMenuAction.isIgnoreOn(doc)){
DoGoodContextMenu.context_menu_ignoreoff.setAttribute('hidden', false);
DoGoodContextMenu.context_menu_ignoreon.setAttribute('hidden', true);
} else {
DoGoodContextMenu.context_menu_ignoreon.setAttribute('hidden', false);
DoGoodContextMenu.context_menu_ignoreoff.setAttribute('hidden', true);
}
if (DoGoodFilter.RegExpWhiteList(doc.location.href)){
DoGoodContextMenu.context_menu_ignoreoff.setAttribute('hidden', true);
DoGoodContextMenu.context_menu_ignoreon.setAttribute('hidden', true);
}
},
/**
* Event handler to open the toolbar menu
*
*/
DoGoodToolbarAction : function() {
var doc = window.content.document;
if (DoGoodReplace.isDogoodObject(doc)) {
DoGoodContextMenu.toolbar_menu_showorigall.setAttribute('disabled', "false");
} else {
DoGoodContextMenu.toolbar_menu_showorigall.setAttribute('disabled', "true");
}
if (DoGoodMenuAction.isIgnoreOn(doc)){
DoGoodContextMenu.toolbar_menu_ignoreoff.setAttribute('disabled', "false");
DoGoodContextMenu.toolbar_menu_ignoreon.setAttribute('disabled', "true");
} else {
DoGoodContextMenu.toolbar_menu_ignoreoff.setAttribute('disabled', "true");
DoGoodContextMenu.toolbar_menu_ignoreon.setAttribute('disabled', "false");
}
if (DoGoodFilter.RegExpWhiteList(doc.location.href)){
DoGoodContextMenu.toolbar_menu_ignoreoff.setAttribute('disabled', "true");
DoGoodContextMenu.toolbar_menu_ignoreon.setAttribute('disabled', "true");
}
}
};
/**
* Context menu action
*/
const DoGoodMenuAction = {
ShowOriginalAll : function() {
DoGoodCookie.createCookie('DoGoodShowAll','yes', 1/86400*8);
DoGoodMenuAction.ShowOriginalObjects();
},
/**
* Function for remove all dogood ads and show original ads
*
* @param {object} event - event object
*/
ShowOriginalObjects : function(doc) {
if (!doc) var doc = window.content.document;
var iframes = doc.getElementsByTagName("iframe");
for (var k=0;k<iframes.length;k++) {
DoGoodMenuAction.ShowOriginalCollection(iframes[k].contentWindow.document.getElementsByTagName("img"), true);
DoGoodMenuAction.ShowOriginalCollection(iframes[k].contentWindow.document.getElementsByTagName("object"), false);
DoGoodMenuAction.ShowOriginalObjects(iframes[k].contentWindow.document);
}
DoGoodMenuAction.ShowOriginalCollection(doc.getElementsByTagName("img"), true);
DoGoodMenuAction.ShowOriginalCollection(doc.getElementsByTagName("object"), false);
},
/**
* Function replace all dogood ad on original ad for collection objects
*
* @param {objects collection} objs - DOM objects collection
* @param {boolean} isParent - for detect parent is replace
*/
ShowOriginalCollection : function(objs, isParent) {
var i = 0;
var len = objs.length;
while (i < len) {
if (objs[i].getAttribute('id') == 'DoGoodObject') {
if (isParent) {
DoGoodMenuAction.ShowOriginal(objs[i].parentNode);
} else {
DoGoodMenuAction.ShowOriginal(objs[i]);
}
DoGoodReplace.currentCount--;
document.getElementById('status-count').value = DoGoodReplace.currentCount; //set to bottom right pannel current count
}
if (objs.length == len) { i++; } else { len = objs.length };
}
},
/**
* Function replace one dogood ad on original ad
*
* @param {object} obj - DOM object
*/
ShowOriginal : function(obj) {
var pr = obj.parentNode;
pr.appendChild(obj.backsrc);
pr.insertBefore(obj.backsrc, obj);
pr.removeChild(obj);
},
/**
* Function for send user report found on the banner
*
* @param {object} event - event object
*/
AdReport : function(event) {
var target = gContextMenu.target;
var page_url = window.content.document.location.href;
var size, click_url, type, src;
if (target.tagName == 'IMG') {
size = target.width + 'x' + target.height;
type = 'image';
src = target.src;
click_url = target.parentNode.href;
target.is_dogood = 1;
}
params = 'page_url=' + page_url + '&click_url=' + click_url + '&size=' + size + '&type=' + type + '&src=' + src;
var xmlhttp = DoGoodFilter.getXmlHttp();
xmlhttp.open("POST", DoGoodReplace.adsserver+'server/userads', true);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
var responseTx = xmlhttp.responseText;
var w = window.open("chrome://dogood/content/dgmessage.xul", "ThanksGood", "chrome,centerscreen,width=390,height=390, resizeble=false");
}
}
};
xmlhttp.send(params);
},
/**
* Save site for ignor
*
* @param {object} event - event object
*/
IgnoreOn : function(event) {
DoGoodCookie.createCookie("dogoodIgnore", 1, 365);
DoGoodMenuAction.ShowOriginalAll(event);
},
/**
* Off ignore for site
*
* @param {object} event - event object
*/
IgnoreOff : function() {
DoGoodCookie.createCookie("dogoodIgnore", 0, 365);
},
/**
* Send users feedback
*/
Feedback : function() {
var daReferrer = document.referrer;
var email = "goodcause@dogoodhq.com";
var errorMsg = "Error message.";
var subject = "I think this is a very good cause to support.";
var body_message = "";
var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+body_message;
win = window.open(mailto_link,'emailWindow');
if (win && win.open &&!win.closed) win.close();
},
/**
* Send users good idea
*/
GoodIdea : function() {
var daReferrer = document.referrer;
var email = "goodidea@dogoodhq.com";
var errorMsg = "Error message.";
var subject = "I have a really good idea to share with everyone.";
var body_message = "";
var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+body_message;
win = window.open(mailto_link,'emailWindow');
if (win && win.open &&!win.closed) win.close();
},
isIgnoreOn : function(doc) {
if (DoGoodCookie.readCookie('dogoodIgnore', doc) == 1) return true;
}
};